LocalAuth
The LocalAuth API is a wrapper around the iOS Local Authentication framework, enabling biometric or passcode authentication in your Scripting app scripts. This document explains how to use the LocalAuth API effectively.
Overview
The LocalAuth module provides methods and properties for checking authentication availability and performing user authentication. It supports biometrics like Face ID, Touch ID, and Optic ID, as well as fallback options like passcodes.
Properties
LocalAuth.isAvailable
- Type:
boolean - Description: Indicates whether authentication can proceed using any available policies.
- Example:
LocalAuth.isBiometricsAvailable
- Type:
boolean - Description: Indicates whether biometric authentication can proceed.
- Example:
LocalAuth.biometryType
- Type:
LocalAuthBiometryType - Description: Specifies the type of biometric authentication supported by the device. Possible values:
"faceID""touchID""opticID""none""unknown"
- Example:
Methods
LocalAuth.authenticate(reason: string, useBiometrics?: boolean): Promise<boolean>
- Description: Authenticates the user with available biometrics or a fallback method (e.g., passcode). Returns a promise that resolves to
trueif authentication succeeds, orfalseif it fails. - Parameters:
reason(string): The message displayed to the user when prompting for authentication. This must not be empty. Example:'Authenticate to access MyScript.'useBiometrics(boolean, optional): Defaults totrue. Iftrue, the method uses biometrics for authentication otherwise, it uses biometrics or a fallback method (e.g., passcode).
- Example:
Usage Examples
Check Biometric Availability
Authenticate with Biometrics
Fallback to Passcode Authentication
Notes
- Always provide a meaningful message in the
reasonparameter to help users understand why authentication is being requested. - Use
LocalAuth.isAvailableandLocalAuth.isBiometricsAvailableto check the availability of authentication options before invokingLocalAuth.authenticate. - Handle both success and failure cases gracefully to provide a seamless user experience.
